package com.ptszyxx.popose.module.main.user;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.ptszyxx.popose.BR;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.constants.BundleConstant;
import com.ptszyxx.popose.databinding.FragmentUserSetBinding;
import com.ptszyxx.popose.module.main.user.vm.UserSetVM;
import com.ysg.base.BaseFragment;
import com.ysg.http.data.AppViewModelFactory;
import com.ysg.utils.YDialogUtil;
import com.ysg.widget.dialog.ConfirmDialog;

public class UserSetFragment extends BaseFragment<FragmentUserSetBinding, UserSetVM> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_user_set;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public UserSetVM initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(UserSetVM.class);
    }

    @Override
    public void initParam() {
        super.initParam();
        Bundle bundle = getArguments();
        if (bundle != null){
            viewModel.userId = bundle.getString(BundleConstant.USER_ID);
            viewModel.dynamicStatus.set(bundle.getString(BundleConstant.DYNAMIC_STATUS));
        }
    }


    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.uc.onBlackEvent.observe(this, o -> showDialogBlack());
    }

    /**
     * 黑名单
     */
    private void showDialogBlack() {
        YDialogUtil.getInstance().showConfirm(getContext(), getResources().getString(R.string.black_dialog_title), getResources().getString(R.string.black_dialog_content))
                .setOnConfirmListener(new ConfirmDialog.OnConfirmListener() {
                    @Override
                    public void onConfirmClick() {
                        viewModel.requestBlack();
                    }
                });
    }


}
